<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增视频')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-video-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">视频名称：</label>
                <div class="col-sm-8">
                    <input name="videoName" class="form-control" type="text">
                </div>
            </div>
            
            <div class="form-group">
	            	<label class="col-sm-3 control-label">上传视频：</label>
		            <div class="col-sm-6">
	                    <input class="form-control" type="file" name="file" id="file" accept=".mp4">
	                    <input type="hidden" name="video" id="video">
	                </div>
	                <div class="col-sm-2">
	                    <button class="btn btn-success fileinput-button" type="button" id="btnimage">上传</button>
	                </div>
	        </div>
	        <div class="form-group" id="videoDiv" name="videoDiv">
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">视频介绍：</label>
                <div class="col-sm-8">
                    <textarea name="introduce" class="form-control" type="textarea"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_able_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/video"
        $("#form-video-add").validate({
            focusCleanup: true
        });

        $('#btnimage').click(function() {
            var val = $("#file").val();
            if (val.length==0) {
                layer.alert("未选择视频");
                return ;
            }
            var formdata = new FormData();
            formdata.append("file", document.getElementById("file").files[0]);
            $.ajax({
                url: ctx + "system/upload/pictrue",
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function(result) {
		            $('#video').val(result);
		            $("#videoDiv").empty();
                	/* $('<label class="col-sm-3 control-label"></label><embed id="videoUrl" autostart="true" width="500" height="300" src="'+result+'"></embed>').appendTo('#videoDiv'); */
                	$('<label class="col-sm-3 control-label"></label><video width="200" height="100" controls="controls"><source src="'+result+'" type="video/mp4" /></video>').appendTo('#videoDiv');
                }
            });
        });
        
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-video-add').serialize());
            }
        }
    </script>
</body>
</html>